package com.lp.easydraw;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Context;
import android.media.projection.MediaProjectionManager;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.ImageButton;
import android.widget.LinearLayout;

import com.lp.easydraw.adapter.ColorGridAdapter;
import com.lp.easydraw.adapter.PaintAdapter;
import com.lp.easydraw.data.DrawColorData;
import com.lp.easydraw.data.PaintType;
import com.lp.easydraw.databinding.ActivityMainBinding;
import com.lp.easydraw.view.EasyDrawView;

import java.util.ArrayList;
import java.util.List;

/**
 * 2024年03月20日10:43:10
 * author:lp
 * 主页面
 */
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private ActivityMainBinding binding;
    private EasyDrawView easyDrawView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
        initView();
    }

    private void initView() {
        easyDrawView = binding.drawView;
        RecyclerView.LayoutManager manager = new GridLayoutManager(this, 2);
        binding.rlColor.setLayoutManager(manager);
        ColorGridAdapter colorGridAdapter = new ColorGridAdapter(colorData ->
                easyDrawView.setPaintColor(ContextCompat.getColor(this, colorData.getColorId())));
        binding.rlColor.setAdapter(colorGridAdapter);

        RecyclerView.LayoutManager linearLayoutManager = new LinearLayoutManager(this, RecyclerView.HORIZONTAL, false);
        binding.rlPaint.setLayoutManager(linearLayoutManager);
        PaintAdapter paintAdapter = new PaintAdapter(paintData -> {
            if (paintData.getPaintType() == PaintType.erase)
                binding.rlColor.setVisibility(View.INVISIBLE);
            else
                binding.rlColor.setVisibility(View.VISIBLE);
            easyDrawView.setPaint(paintData.getPaintType());
        });
        binding.rlPaint.setAdapter(paintAdapter);
    }


    @Override
    public void onClick(View view) {

    }
}